
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="description" content="">
    <title>Off Canvas Template for Bootstrap</title>
    <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <link href="http://v3.bootcss.com/assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet">
    <link href="/static/pc/cmgd.css" rel="stylesheet">
    <link rel="stylesheet" href="/static/pc/swiper.3.2.0.min.css">

    <link rel="stylesheet" type="text/css" href="/static/admin/webupload/webuploader.css">
    <link rel="stylesheet" type="text/css" href="/static/admin/webupload/style.css">

    <!--[if lt IE 9]><script src="http://v3.bootcss.com/assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
    <script src="http://v3.bootcss.com/assets/js/ie-emulation-modes-warning.js"></script>
    <!--[if lt IE 9]>
    <script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

    <script src="/static/admin/js/jquery.min.js?v=2.1.4"></script>
    <script src="/static/admin/js/jquery.form.js"></script>
    <script src="/static/admin/js/plugins/layer/laydate/laydate.js"></script>
    <script src="/static/pc/js/layer/layer.js"></script>
    <script src="/static/admin/js/laypage/laypage.js"></script>
    <script src="/static/admin/js/laytpl/laytpl.js"></script>
    <link href="/static/admin/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">

    <style>
        .list-group-item:first-child {border-radius: 0px;   }
        .fa{padding-right: 5px;font-size:22px;}
        .list-group-item{font-size:16px; border-top:0px;}
        .panel-heading{background: #f5f5f5;}

        .panel-primary>.panel-heading {
            color: #fff;
            background-color: #2fab87;
            border-color: #2fab87;
        }

        .panel-primary {
            border-color: #2fab87;
        }


    </style>
</head>

<body >
{include file="public/header2" /}
<div class="container body_bg" style="margin-top:80px;">

    <div class="row row-offcanvas row-offcanvas-right">
        <div class="col-xs-3 col-sm-3 sidebar-offcanvas" id="sidebar">

            <div style="width: 100%;height:80px;border:1px solid #ddd;padding-top: 10px;padding-left: 10px;" >
                <div style="width:60px;float: left;margin-right:10px;">
                    <img src="/uploads/face/{$member.head_img}" style="width: 60px;height: 60px;">
                </div>
                <div style="float: left;width: 178px;">
                    <div style="width: 178px;overflow: hidden;padding-top: 3px;">{$member.nickname}</div>
                    <div style="width: 178px;overflow: hidden;padding-top: 12px;">ID:{$member.account}</div>
                </div>
            </div>


            <div class="list-group">
                <a href="{:url('write')}" class="list-group-item "><i class="fa fa-pencil-square-o "></i>写文章</a>
                <a href="{:url('write_debate')}" class="list-group-item"><i class="fa fa fa-comment-o "></i>论话题</a>
                <a href="{:url('myessay')}" class="list-group-item"><i class="fa fa-file-text-o "></i>已投征文</a>
                <a href="{:url('draft')}" class="list-group-item"><i class="fa fa-folder-open-o "></i>我的草稿箱</a>
                <a href="{:url('collect')}" class="list-group-item"><i class="fa fa-heart-o "></i>我的收藏</a>
                <a href="{:url('temp_message')}" class="list-group-item"><i class="fa fa-bell-o "></i>模板消息</a>
            </div>
        </div><!--/.sidebar-offcanvas-->
        <div class="col-xs-12 col-sm-9">

            <div class="panel panel-primary">
                <div class="panel-heading">
                    写文章
                </div>
                <div class="panel-body">
                    <div class="wrapper wrapper-content animated fadeInRight">
                        <div class="row">
                            <div class="col-sm-12">
                                <div class="ibox float-e-margins">
                                    <div class="ibox-title">
                                        <!--<div class="ibox-tools">-->
                                            <!--<a class="collapse-link">-->
                                                <!--<i class="fa fa-chevron-up"></i>-->
                                            <!--</a>-->
                                            <!--<a class="dropdown-toggle" data-toggle="dropdown" href="form_basic.html#">-->
                                                <!--<i class="fa fa-wrench"></i>-->
                                            <!--</a>-->
                                            <!--<a class="close-link">-->
                                                <!--<i class="fa fa-times"></i>-->
                                            <!--</a>-->
                                        <!--</div>-->
                                    </div>
                                    <div class="ibox-content">
                                        <form class="form-horizontal m-t" name="add" id="add" method="post" action="write">

                                            <div class="form-group">
                                                <label class="col-sm-3 control-label">标题：</label>
                                                <div class="input-group col-sm-4">
                                                    <input id="title" type="text" class="form-control" name="title" placeholder="输入文章标题" value="{$info.title}">
                                                </div>
                                            </div>
                                            <div class="hr-line-dashed"></div>
                                            <div class="form-group">
                                                <label class="col-sm-3 control-label">所属分类：</label>
                                                <div class="input-group col-sm-4">
                                                    <select class="form-control m-b chosen-select" name="cate_id" id="cate_id">
                                                        <option value="">==请选择==</option>
                                                        {if !empty($cate)}
                                                        {foreach name="cate" item="vo"}
                                                        <option value="{$vo.id}"  {if condition="$info.cate_id == $vo.id"} selected{/if}   >{$vo.name}</option>
                                                        {/foreach}
                                                        {/if}
                                                    </select>
                                                </div>
                                            </div>
                                            <!--<div class="hr-line-dashed"></div>-->
                                            <!--<div class="form-group">-->
                                            <!--<label class="col-sm-3 control-label">关键字：</label>-->
                                            <!--<div class="input-group col-sm-4">-->
                                            <!--<input id="keyword" type="text" class="form-control" name="keyword" placeholder="输入文章关键字">-->
                                            <!--</div>-->
                                            <!--</div>-->
                                            <div class="hr-line-dashed"></div>
                                            <div class="form-group">
                                                <label class="col-sm-3 control-label">描述：</label>
                                                <div class="input-group col-sm-4">
                                                    <textarea type="text" rows="5" name="remark" id="remark" placeholder="输入文章描述" class="form-control">{$info.remark}</textarea>
                                                </div>
                                            </div>
                                            <div class="hr-line-dashed"></div>
                                            <div class="form-group">
                                                <label class="col-sm-3 control-label">封面：</label>
                                                <div class="input-group col-sm-4">
                                                    <input type="hidden" id="data_photo" name="photo" value="{$info.photo}">
                                                    <div id="fileList" class="uploader-list" style="float:right"></div>
                                                    <div id="imgPicker" style="float:left">选择图片</div>
                                                    <img id="img_data" height="100px" style="float:left;margin-left: 50px;margin-top: -10px;" src="/uploads/images/{$info.photo}"  onerror="this.src='/static/admin/images/no_img.jpg'"     />
                                                </div>
                                            </div>
                                            <div class="hr-line-dashed"></div>
                                            <div class="form-group">
                                                <label class="col-sm-3 control-label " for="myEditor">内容：</label>
                                                <div class="input-group col-sm-9">
                                                    <script src="/static/admin/ueditor/ueditor.config.js" type="text/javascript"></script>
                                                    <script src="/static/admin/ueditor/ueditor.all.js" type="text/javascript"></script>
                                                    <textarea name="content" style="width:90%" id="myEditor">{$info.content}</textarea>
                                                    <script type="text/javascript">
                                                        var editor = new UE.ui.Editor();
                                                        editor.render("myEditor");
                                                    </script>
                                                </div>
                                            </div>

                                            <div class="hr-line-dashed"></div>
                                            <div class="form-group">
                                                <div class="col-sm-4 col-sm-offset-3">

                                                    <input type="hidden" name="id" value="{$info.id}">

                                                    <button class="btn btn-primary" type="submit"><i class="fa fa-save"></i> 提交</button>&nbsp;&nbsp;&nbsp;

                                                    <a class="btn btn-primary" href="javascript:;" onclick="save_cg()"><i class="fa fa-save"></i> 保存草稿箱</a>
                                                </div>
                                            </div>
                                        </form>
                                    </div>
                                </div>

                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div><!--/row-->

    <hr>

    <footer style="text-align: center;">
        <p>&copy; Company 2017</p>
    </footer>

</div><!--/.container-->


<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->

<script type="text/javascript" src="/static/admin/webupload/webuploader.min.js"></script>

<script type="text/javascript">
    var $list = $('#fileList');
    //上传图片,初始化WebUploader
    var uploader = WebUploader.create({

        auto: true,// 选完文件后，是否自动上传。
        swf: '/static/admin/js/webupload/Uploader.swf',// swf文件路径
        server: "{:url('Mobile/Upload/upload')}",// 文件接收服务端。
        duplicate :true,// 重复上传图片，true为可重复false为不可重复
        pick: '#imgPicker',// 选择文件的按钮。可选。

        accept: {
            title: 'Images',
            extensions: 'gif,jpg,jpeg,bmp,png',
            mimeTypes: 'image/jpg,image/jpeg,image/png'
        },

        'onUploadSuccess': function(file, data, response) {
            $("#data_photo").val(data._raw);
            $("#img_data").attr('src', '/uploads/images/' + data._raw).show();
        }
    });

    uploader.on( 'fileQueued', function( file ) {
        $list.html( '<div id="' + file.id + '" class="item">' +
                '<h4 class="info">' + file.name + '</h4>' +
                '<p class="state">正在上传...</p>' +
                '</div>' );
    });

    // 文件上传成功
    uploader.on( 'uploadSuccess', function( file ) {
        $( '#'+file.id ).find('p.state').text('上传成功！');
    });

    // 文件上传失败，显示上传出错。
    uploader.on( 'uploadError', function( file ) {
        $( '#'+file.id ).find('p.state').text('上传出错!');
    });

    function save_cg(){
        $('#add').attr('action','cg_add_article').submit();
    }

    $(function(){
        $('#add').ajaxForm({
            beforeSubmit: checkForm, // 此方法主要是提交前执行的方法，根据需要设置
            success: complete, // 这是提交后的方法
            dataType: 'json'
        });

        function checkForm(){

          var act =    $('#add').attr('action');

            if(act=='write'){

                if( '' == $.trim($('#title').val())){
                layer.msg('标题不能为空', {icon: 5,time:1500,shade: 0.1}, function(index){
                    layer.close(index);
                });
                return false;
            }

            if( '' == $.trim($('#cate_id').val())){
                layer.msg('分类不能为空', {icon: 5,time:1500,shade: 0.1}, function(index){
                    layer.close(index);
                });
                return false;
            }

            if( '' == $.trim($('#remark').val())){
                layer.msg('描述不能为空', {icon: 5,time:1500,shade: 0.1}, function(index){
                    layer.close(index);
                });
                return false;
            }

            if( '' == $.trim($('#data_photo').val())){
                layer.msg('请上传图片', {icon: 5,time:1500,shade: 0.1}, function(index){
                    layer.close(index);
                });
                return false;
            }

//            if( '' == $.trim($('#content').val())){
//                layer.msg('内容不能为空', {icon: 5,time:1500,shade: 0.1}, function(index){
//                    layer.close(index);
//                });
//                return false;
//            }

            }




        }

        function complete(data){
            var act =    $('#add').attr('action');
            if(data.code == 1){
                layer.msg(data.msg, {icon: 6,time:1500,shade: 0.1}, function(index){
                    layer.close(index);

                    if(act == 'cg_add_article'){
                        window.location.href="{:url('article/draft')}";
                    }
                    //window.location.href="{:url('article/index')}";

                });
            }else{
                layer.msg(data.msg, {icon: 5,time:1500,shade: 0.1}, function(index){
                    layer.close(index);
                });
                return false;
            }
        }

    });



</script>
</body>
</html>
